package com.lengxf.minio.model;

import io.minio.credentials.Credentials;
import io.minio.credentials.Provider;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class CredentialsDTO implements Provider {

    private String accessKeyId;

    private String secretAccessKey;

    private String sessionToken;

    private Integer expire;

    public CredentialsDTO(String accessKeyId, String secretAccessKey, String sessionToken) {
        this.accessKeyId = accessKeyId;
        this.secretAccessKey = secretAccessKey;
        this.sessionToken = sessionToken;
        this.expire = 0;
    }

    public CredentialsDTO(Credentials credentials, Integer expire) {
        this.accessKeyId = credentials.accessKey();
        this.secretAccessKey = credentials.secretKey();
        this.sessionToken = credentials.sessionToken();
        this.expire = expire;
    }

    @Override
    public Credentials fetch() {
        return new Credentials(accessKeyId, secretAccessKey, sessionToken, null);
    }
}
